<?php
/**
 * Created by PhpStorm.
 * User: kkw
 * Date: 2019/1/30
 * Time: 22:14
 */
namespace kkw\goods\response;
use kkw\user\Util;
use kkw\goods\table\GoodsTable;
use suda\core\Request;
use suda\core\Response;

class UpdateGoodsResponse extends  Response
{
    public function onRequest(Request $request)
    {
        Util::printHeader();
        $json = Request::json();
        $id= $json['id'];
        $title= $json['title'];
        $price = $json['price'];
        $qq = $json['qq'];
        $address = $json['address'];
        $describe = $json['describe'];
        $mobile = $json['mobile'];
        $goods = new GoodsTable();
        try {
            $goods->update(['title'=>$title,'price' => $price, 'qq'=>$qq, 'address'=>$address, 'describe'=>$describe, 'mobile'=>$mobile],['id'=>$id]);
        } catch (\suda\exception\SQLException $e) {
            $this->json(['code'=>$e->getCode(),'message'=> '更新数据失败']);
        }
        $this->json(['code'=>0,'message'=>'更新数据成功']);
    }
}